﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using IDAL.RF.Repair;
using Model.RF.Repair;

namespace DAL.RF.Repair
{
    public class RepairCancel : BaseRepository_DT<RepairCancelInfo>, IRepairCancel
    {
        #region 静态变量定义部分
        private const string PARM_ID = "@ID";
        private const string PARM_PRODUCTSN = "@ProductSN";
        private const string PARM_USERID = "@UserID";
        #endregion
        
        #region 操作录入部分
        public bool RepairCancel_Add(string productSN, string userID)
        {
            try
            {
                SqlParameter[] Parms = GetSNUIDParameters();
                Parms[0].Value = productSN;
                Parms[1].Value = userID;
                SqlCommand cmd = new SqlCommand();
                foreach (SqlParameter parm in Parms)
                {
                    cmd.Parameters.Add(parm);
                }
                ExecuteCommand(cmd, "RepairCancel_Insert");
                return true;
            }
            catch
            {
                throw;
            }
        }
        #endregion

        #region 检索部分
        public IList<RepairCancelInfo> LoadEntities()
        {
            return null;
        }

        public RepairCancelInfo LoadEntity<T1>(T1 id)
        {
            return null;
        }

        public IList<RepairCancelInfo> RepairCancel_GetbySN(string productSN)
        {
            SqlParameter Parm = new SqlParameter(PARM_PRODUCTSN, SqlDbType.NVarChar, 50);
            Parm.Value = productSN;
            return ExcuteSqlToGetEntities("RepairCancel_selectbySN", Parm);
        }

        public IList<RepairCancelInfo> RepairCancel_GetbyDT(DateTime dt1, DateTime dt2)
        {
            SqlParameter[] Parms = GetDTParameters();
            Parms[0].Value = dt1;
            Parms[1].Value = dt2;
            return ExcuteSqlToGetEntities("RepairCancel_selectbyDT", Parms);
        }
        #endregion

        #region 参数部分
        public SqlParameter[] GetSNUIDParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[] 
            {
                new SqlParameter(PARM_PRODUCTSN, SqlDbType.NVarChar, 50),
                new SqlParameter(PARM_USERID, SqlDbType.NVarChar, 10)
            };
            return parms;
        }
        #endregion

        #region 重写基类部分
        public override RepairCancelInfo GetEntityRecord(SqlDataReader rdr)
        {
            RepairCancelInfo pro = new RepairCancelInfo()
            {
                ID = rdr.GetInt32(0),
                ProductSN = rdr.GetValue(1).ToString(),
                RecordTime = rdr.GetDateTime(2),
                UserID=rdr.GetValue(3).ToString(),
                LockorRepairTime=rdr.GetDateTime(4),
                LockSteporRemark=rdr.GetValue(5).ToString(),
                CancelType=rdr.GetInt32(6)
            };
            return pro;
        }

        public override RepairCancelInfo GetEntityRecord()
        {
            RepairCancelInfo pro = new RepairCancelInfo();
            return pro;
        }

        public override string GetInsertsp()
        {
            return null;
        }

        public override string GetUpdatesp()
        {
            return null;
        }

        public override string GetDeletesp()
        {
            return null;
        }

        public override SqlParameter GetParameter()
        {
            SqlParameter Parm = new SqlParameter(PARM_ID, SqlDbType.Int, 4);
            return Parm;
        }

        public override SqlParameter[] GetParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]{};
            return parms;
        }

        public override void SetParameters(RepairCancelInfo Entity, params SqlParameter[] Parms)
        {
            
        }
        #endregion
    }
}
